const jwt = require('jsonwebtoken');
//检查token是否过期
module.exports = async (ctx, next) =>{
    //拿到token

    const token = ctx.get('Authorization');
    if(token === ''){
        ctx.throw(401, '没有请求头');
    }
    let tokenContent;
    try{
        tokenContent = await jwt.verify(token, 'sinner77'); //如果token过期或验证失败，将抛出错误
    } catch (err) {
        ctx.throw(401, 'token值无效');
    }
    await next();

};
